package com.wangshuqi.spring;

import com.wangshuqi.spring.config.SpringConfig;
import com.wangshuqi.spring.dao.UserDAO;
import com.wangshuqi.spring.entity.User;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import java.util.List;

/**
 * spring-junit5的单元测试使用案例
 *
 * @author codewsq
 * @date 2022/4/25 0025 21:41
 */
// 方式1：
//@ExtendWith({SpringExtension.class})
//@ContextConfiguration(value = {"classpath:config/spring.xml"}) // xml配置文件方式启动spring单元测试
// 方式2：
//@SpringJUnitConfig(locations = {"classpath:config/spring.xml"}) // xml配置文件方式启动spring单元测试
@SpringJUnitConfig(classes = {SpringConfig.class}) // 注解配置类的方式启动spring单元测试
public class SpringTestWithJunit5 {

    @Autowired
    private UserDAO userDAO;

    @Test
    public void test() {
        User user = userDAO.selectById(29);
        System.out.println(user);
        Integer count = userDAO.selectCountByName("zhangsan");
        System.out.println(count);

        List<User> list = userDAO.selectByName("zhangsan");
        list.forEach(System.out::println);
    }

}
